﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MISAPP.MISInterface;

/// <summary>
/// 給有要使用Autocomplete 的網頁來使用
/// </summary>
public class ViewAC : System.Web.UI.Page
{
	public ViewAC()
	{
		//
		// TODO: 在此加入建構函式的程式碼
		//
	}

    protected void PutAutoCompleteData(iAutoComplete p_ac)
    {
        if (Request.QueryString.Count.Equals(0))
        { return; }
        string qry = Request.QueryString["q"].ToString();
        if (string.Empty == qry)
        {
            return;
        }
        System.Data.DataTable dt = p_ac.GetAutoCompleteTable(qry);
        if ((dt == null) || (dt.Rows.Count.Equals(0)))
        {
            Response.Write(String.Format("{0}|{1}", "No match", "No match"));
            return;
        }
        List<string> lst = new List<string>();
        int i = 0;
        bool isOutPut = false;
        foreach (System.Data.DataRow row in dt.Rows)
        {
            i++;
            lst.Add(String.Format("{0}|{1}", row[0], row[1]));
            if (i.Equals(10))
            {
                Response.Write(String.Join(Environment.NewLine, lst.ToArray()));
                isOutPut = true;
                break;
            }
        }
        if ((lst.Count > 0) & (isOutPut == false))
        {
            Response.Write(String.Join(Environment.NewLine, lst.ToArray()));
        }
    }
}
